import axios from 'axios';
import router from '@/router';
import store from '../stores/stores.js';
import { Message } from 'view-design';

import Vue from 'vue';
const status = {
  400: '请求出现错误',
  401: '没有提供认证信息',
  403: '没有权限',
  404: '请求内容不存在',
  405: '请求方式错误',
  406: '请求的资源并不符合要求',
  408: '客户端请求超时',
  413: '请求体过大',
  415: '类型不正确',
  416: '请求的区间无效',
  501: '请求还没有被实现',
  502: '网关错误',
  503: '服务暂时不可用',
  504: '服务连接失败',
  505: '请求的 HTTP 版本不支持',
};

let cancel;
let msg = '';




let reqList = new Set();
/**
 * 阻止重复请求
 * @param {array} reqList - 请求缓存列表
 * @param {string} url - 当前请求地址
 * @param {function} cancel - 请求中断函数
 * @param {string} errorMessage - 请求中断时需要显示的错误信息
 */
const stopRepeatRequest = function (reqList, url, cancel, errorMessage) {
  const errorMsg = errorMessage || '';
    if (reqList.has(url)) {
      cancel(errorMsg)
    }else {
      reqList.add(url)
    }
}
/**
 * 允许某个请求可以继续进行
 * @param {array} reqList 全部请求列表
 * @param {string} url 请求地址
 **/
const allowRequest = function (reqList, url) {
    if (reqList.has(url)) {
      reqList.delete(url)
    }
}



const service = axios.create({
  //  baseURL: process.env.BASE_API
});




/*
* 处理cookie
* */


var acookie = document.cookie.split("; ");
var xcookie = "";
function getck(sname) {//获取单个cookies
  for (var i = 0; i < acookie.length; i++) {
    var arr = acookie[i].split("=");
    if (sname == arr[0]) {
      if (arr.length > 1)
        return arr[1];
      else
        return "";
    }
  }
  return "";
}

// request请求拦截器
service.interceptors.request.use(
     (config) => {
                 let token = sessionStorage.getItem('PIECloud-Token');
                 if (token) {
                   config.headers.Authorization = `${token}`;
                 }else{
                     if (productionOrEngine === "production") {
                         router.push({name: "login"});
                     }
                 }
                 // 添加 x-token
                 if (productionOrEngine!=="production") {
                   if (xcookie) {
                     config.headers["x-token"] = `${xcookie}`;
                   } else {
                     xcookie = getck("engine-token");
                     config.headers["x-token"] = `${xcookie?xcookie:""}`;
                   }
                 }


              /* let cancel;
               // 阻断重复请求，设置cancelToken对象
               config.cancelToken = new axios.CancelToken(function(c) {cancel = c})
               let {url, method, params, data} = config;
               let onlyData = [url, method, JSON.stringify(params), JSON.stringify(data)].join('&');
               // 阻止重复请求。当上个请求未完成时，相同的请求不会进行
               stopRepeatRequest(reqList, onlyData, cancel, `请勿重复操作！`)*/

               return config;
     },
     (error) => {
       return Promise.reject(error);
     }
);


// response 响应拦截器
service.interceptors.response.use(
     (response) => {

                 // 请求完成后 1秒内不许再次请求， 1秒后在清除请求。
            //    allowRequest(reqList, response.config.url)

                 const {data, status, url, config} = response;
                 return {data, status, config};
               },
     (error) => {

                 // 请求完成后 1秒内不许再次请求， 1秒后在清除请求。
                  /*   if (axios.isCancel(error)) {
                         console.log(error);
                     }*/
                     // 请求完成后 1秒内不许再次请求， 1秒后在清除请求。
                     //allowRequest(reqList, error.config.url)
                     if ((error.response ? error.response.status : error.code) == 401) {
                         store.commit("logout");
                         //router.push({path: '/pages/login'});
                         if (productionOrEngine === "production") {
                             router.push({name: 'login'});
                         } else {
                             window.location.href = engineLoginUrl;
                         }
                     }
                     /*  if ( error.response.status===403) {
                         Message.error({
                               content: "对不起，您无权查看，请联系管理员开通权限!",
                               duration: 20,
                             });
                         return Promise.reject(error);
                       }*/
                     return Promise.reject(error);
     }
);


export const req = {
  get(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'get',
        url,
        params: param,
  /*      cancelToken: new CancelToken((c) => {cancel = c;})*/
      }).then((res) => {
          if (res===undefined){reject();return }
         /* if (res.data) {resolve(res);return;}*/
          if (res.status == 200 || res.data instanceof Array) {
            resolve(res)
          } else {
            reject(res.data.msg)
          }
        })
          .catch((error) => {
          if (process.env.NODE_ENV === 'production') {
            return
          }
          if (error.response) {
            msg = status[error.response.status]
          } else {
            msg = error.message
          }
          reject(error)
        })


    })
  },
  post(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'post',
        url,
        data: param,
      }).then((res) => {
          if ((res.status == 200 && res.data) || (res.status == 200 && res.data == null)) {
            if ((res.data && typeof res.data.result == 'string') || (res.data && res.data.msg)) {
              // Message.success(res.data.result || res.data.msg)
            }
            resolve(res)
          } else {
            resolve(res)
            reject(res.data.msg)
          }
        })
        .catch((error) => {
          if (process.env.NODE_ENV === 'production') return
          if (error.response) {
            msg = status[error.response.status]
          } else {
            msg = error.message
          }
          reject(error)
        })
    })
  },
  postText(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'post',
        url,
        headers:{"Content-Type":"application/json;charset=UTF-8"},
        data: param,
      }).then((res) => {
          if ((res.status == 200 && res.data) || (res.status == 200 && res.data == null)) {
            if ((res.data && typeof res.data.result == 'string') || (res.data && res.data.msg)) {
              // Message.success(res.data.result || res.data.msg)
            }
            resolve(res)
          } else {
            resolve(res)
            reject(res.data.msg)
          }
        })
        .catch((error) => {
          if (process.env.NODE_ENV === 'production') return
          if (error.response) {
            msg = status[error.response.status]
          } else {
            msg = error.message
          }
          reject(error)
        })
    })
  },
  form(url, e, param = {}, type = 'post') {
    delete param._rowKey
    delete param._index
    let formData = new FormData()
    let keys = Object.keys(param)
    keys.map((v) => {
      formData.append(v, param[v])
    })
    if (e && e.length) { // 判断是否是多图上传 多图则循环添加进去
      e.forEach(item => {
        formData.append("fileList", item) //第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      })
    } else {
      formData.append("file", e)
    }
    return new Promise((resolve, reject) => {
      service({
        method: type,
        url,
        params: formData,
        data: formData
      })
        .then((res) => {
          if ((res.status == 200 && res.data && res.data.code == 0) || (res.status == 200 && res.data == null)) {
            if ((res.data && typeof res.data.result == 'string') || (res.data && res.data.msg)) {
              // Message.success(res.data.result || res.data.msg)
            }
            resolve(res)
          } else {
            resolve(res)
            reject(res.data.msg)
          }
        })
        .catch((error) => {
          if (process.env.NODE_ENV === 'production') return
          if (error.response) {
            msg = status[error.response.status]
          } else {
            msg = error.message
          }
          reject(error)
        })
    })
  },
  patch(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'patch',
        url,
        data: param
      })
        .then((res) => {
          if ((res.status == 200)) {
            resolve(res)
          } else {
            resolve(res)
            reject(res.data.msg)
          }
        })
        .catch((error) => {
          if (process.env.NODE_ENV === 'production') return
          reject(error)
        })
    })
  },
  delete(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'delete',
        url,
        params: param,
       /* cancelToken: new CancelToken((c) => {
          cancel = c
        })*/
      })
        .then((res) => {
         /* if (!res.data) {resolve(res);return; }*/
          if (res.status == 200) {
            resolve(res)
          } else {
            reject(res.data.msg)
          }
        })
        .catch((error) => {
          if (process.env.NODE_ENV === 'production') return
          reject(error)
        })
    })
  },
  put(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'put',
        url,
        data: param,
       /* cancelToken: new CancelToken((c) => {
          cancel = c
        })*/
      })
        .then((res) => {
         /* if (!res.data) {
            resolve(res)
            return
          }*/
          if (res.status == 200) {
            resolve(res)
          } else {
            reject(res.data.msg)
          }
        })
        .catch((error) => {
          if (process.env.NODE_ENV === 'production') return
          reject(error)
        })
    })
  },


}






//取消请求
/*

const CANCEL_TOKEN = axios.CancelToken;
/!**
 * vue添加原型属性，记录请求信息
 *!/
Vue.prototype.$httpRequestList = [];
axios({
  url: url,
  methods: 'POST',
  data: options,
  cancelToken: new CANCEL_TOKEN(c => { //强行中断请求要用到的，记录请求信息
    Vue.prototype.$httpRequestList.push(c);
  })
}).then(res => {}).catch(err => {
  if (err.message == "interrupt") {
    console.log('已中断请求');
    return;
  }
})
/!**
 * 在路由切换之前检测来中断上个页面的请求
 *!/
router.beforeEach((to, from, next) => {   //路由切换检测是否强行中断，
  if(Vue.$httpRequestList.length>0){        //强行中断时才向下执行
    Vue.$httpRequestList.forEach(item=>{
      item('interrupt');//给个标志，中断请求
    })
  }
  next();
});
*/


/*

import axios from 'axios';
import router from '@/router'
import store from '../stores/stores.js'
import Vue from 'vue'

const status = {
  400: '请求出现错误',
  401: '没有提供认证信息',
  403: '没有权限',
  404: '请求内容不存在',
  405: '请求方式错误',
  406: '请求的资源并不符合要求',
  408: '客户端请求超时',
  413: '请求体过大',
  415: '类型不正确',
  416: '请求的区间无效',
  501: '请求还没有被实现',
  502: '网关错误',
  503: '服务暂时不可用',
  504: '服务连接失败',
  505: '请求的 HTTP 版本不支持'
}


// 创建axios实例
let cancel;
let promiseArr = {}
let msg = ''


const CancelToken = axios.CancelToken

const service = axios.create()


function destroy(url) {
  delete promiseArr[url]
  if (!Object.keys(promiseArr).length) {
    // Spin.hide()
  }
}


/!*
* 臧仙居封装loading，
* 使用方式：
* 1  请求时请求参数中加入  loadingdom：class  //class为要加载loading的dom元素上的样式名称
* 2  如果请求中没有loadingdom参数，则默认使用在dom元素上有 loadingdom类 的元素
* *!/


import {Loading} from 'element-ui';
let loadingRequestCount = 0;
let loadingInstance;
// 3.编写一个显示loading的函数 并且记录请求次数 ++
const showLoading = (data) => {
  if (loadingRequestCount === 0) {
    let loading = data.loadingdom ? "." + data.loadingdom : '.loadingdom';
    loadingInstance = Loading.service({target: loading  });
  }
  loadingRequestCount++
};


// 4.编写一个隐藏loading的函数，并且记录请求次数
const hideLoading = () => {
  if (loadingRequestCount <= 0) return
  loadingRequestCount--
  if (loadingRequestCount === 0) {
    Vue.nextTick(() => {  //以服务的方式调用的 Loading 需要异步关闭
      loadingInstance.close();
    });
  }
};

// request请求拦截器
service.interceptors.request.use(
     (config) => {
       // if (config.method == 'get') {
       //     config.data = true
       // }
       // config.headers['H-TOKEN'] = '111'
       // if (promiseArr[config.url]) {
       // 	promiseArr[config.url]('操作取消')
       // 	promiseArr[config.url] = cancel
       // } else {
       // 	promiseArr[config.url] = cancel
       // }
       // 添加全局的loading...

       // let user = store.state.user
       // let token = null
       // if (user != null) {
       //   token = user.token
       // }
       let token = sessionStorage.getItem('PIECloud-Token');
       if (token) config.headers.Authorization = `${token}`;
       if (!Object.keys(promiseArr).length) {
         // Spin.show() // 不建议开启，因为界面不友好
       }
       promiseArr[config.url] = true;

       // if (config.params && config.params._loadingContainer) {
       //   showFullScreenLoading(config.params._loadingContainer)
       // } else
       //   showFullScreenLoading()


       // //       开启loading
       // showLoading(config);
       return config;
     },
     (error) => {
       // Do something with request error
       // router.push({
       // 	path: '/login'
       // })
       //判断当前请求是否设置了不显示Loading
       // if (config.headers.showLoading !== false) {
       //   hideLoading();
       // }
       console.log('error: ', error)
       return Promise.reject(error)
     }
)
// response 响应拦截器
service.interceptors.response.use(
     (response) => {
       const {
         data,
         status,
         url,
         config
       } = response
       destroy(url)
       //响应拦截进来隐藏loading效果，此处采用延时处理是合并loading请求效果，避免多次请求loading关闭又开启   合并loading请求效果  避免重复请求
       // if (response.config.showLoading) {
       //   tryHideFullScreenLoading()
       //  }
       // tryHideFullScreenLoading()
       /!**
        * code为非20000是抛错 可结合自己业务进行修改
        *!/
       /!*  setTimeout(() => {
           hideLoading()
         }, 300);*!/
       // Spin.hide() // 不建议开启，因为界面不友好
       return {
         data,
         status,
         config
       }
     },
     (error) => {
       //判断当前请求是否设置了不显示Loading（不显示自然无需隐藏）
       // if(error.config.headers.showLoading !== false){
       //   hideLoading();
       // }
       // tryHideFullScreenLoading()
       if ((error.response ? error.response.status : error.code) == 401) {
         store.commit("logout")
         router.push({
           path: '/pages/login'
         })
         // window.location.href ="http://cloud.piesat.cn/#/login"
         // window.sessionStorage.removeItem("PIECloud-Token");
         // window.sessionStorage.removeItem("USERID");
         // window.sessionStorage.setItem(
         //   "historyUrl",
         //   "http://cloud.piesat.cn/ortho/"
         // );
       }
       // Spin.hide() // 不建议开启，因为界面不友好
       console.dir(error)
       // Message.error(status[error.response.status])
       console.group(error.config.url)
       console.log(
            '%cdata：' + (error.response == undefined ? error.name : error.response.config.data),
            'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
       )
       console.log(
            '%cerror：' + (error.response ? error.response.data.error : error.message),
            'background-color:#DC5145;color:white;height:16px;border-radius:4px;padding:2px 4px;'
       )
       console.log(
            '%cstatus：' + (error.response ? error.response.status : error.code),
            'background-color:#FDCC41;color:white;height:16px;border-radius:4px;padding:2px 4px;'
       )
       console.log(
            '%cmessage：' + error.message,
            'background-color:#4D8BF2;color:white;height:16px;border-radius:4px;padding:2px 4px;'
       )
       console.log('%c-------------------------------------------------------------------', 'font-weight:700;')
       console.groupEnd()

       /!*   setTimeout(() => {
            hideLoading()
          }, 300);*!/
       return Promise.reject(error)
     }
)
export const req = {
  //get请求
  get(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'get',
        url,
        params: param,
        cancelToken: new CancelToken((c) => {
          cancel = c
        })
      })
           .then((res) => {
             console.log('res: ', res)
             if (!res.data) {
               resolve(res)
               return
             }
             if (res.status == 200 || res.data instanceof Array) {
               console.groupCollapsed(url + '  %cGET', 'font-weight:900;color:red;')
               if (res.data.result instanceof Array) {
                 res.data.result.map((v) => {
                   console.log(
                        '%cdataObj：' + JSON.stringify(v, null, 2),
                        'background-color:#fff;color:black;height:16px;border-radius:4px;padding:2px 4px;'
                   )
                 })
               } else if (res.data.result instanceof Array) {
                 console.log(
                      '%cdataObj：' + JSON.stringify(res.data.result, null, 2),
                      'background-color:#fff;color:black;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               } else if (res.data.result instanceof String) {
                 console.log(
                      '%cdata：' + res.data.result,
                      'background-color:#fff;color:black;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               } else {
                 console.log(
                      '%cdata：' + res.data.result,
                      'background-color:#fff;color:black;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               }
               console.log(
                    '%c-------------------------------------------------------------------',
                    'font-weight:700;'
               )
               console.groupEnd()
               if (res.data.result instanceof String) {
                 // Message.success(res.data.result)
               }
               resolve(res)
             } else {
               // Message.error(res.data.msg || '错误')
               reject(res.data.msg)
             }
           })
           .catch((error) => {
             if (process.env.NODE_ENV === 'production') return
             console.dir(error)
             console.group('%c' + url + '  GET', 'font-weight:900;color:red;')
             console.log(
                  '%cdata：' + (error.response == undefined ? error.name : error.response.config.data),
                  'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cerror：' + (error.response ? error.response.data.error : error.message),
                  'background-color:#DC5145;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cstatus：' + (error.response ? error.response.status : error.code),
                  'background-color:#FDCC41;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cmessage：' + error.message,
                  'background-color:#4D8BF2;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%c-------------------------------------------------------------------',
                  'font-weight:700;'
             )
             console.groupEnd()
             if (error.response) {
               msg = status[error.response.status]
             } else {
               msg = error.message
             }
             reject(error)
           })
    })
  },
  //post请求
  post(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'post',
        url,
        data: param,

      })
           .then((res) => {
             // let urlList = url.split('/')
             // console.log("TCL: post -> url", )
             // if(urlList[urlList.length - 1]=='loginSelect'){

             // }
             console.log('res: ', res)
             if ((res.status == 200 && res.data) || (res.status == 200 && res.data == null)) {
               console.groupCollapsed('%c' + url + '  POST', 'font-weight:900;')
               if (res.data && res.data.result instanceof Array) {
                 res.data.result.map((v) => {
                   console.log(
                        '%cdataObj：' + JSON.stringify(v, null, 2),
                        'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                   )
                 })
               } else if (res.data && res.data.result instanceof Object) {
                 console.log(
                      '%cdataObj：' + JSON.stringify(res.data.result, null, 2),
                      'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               } else if (res.data && res.data.result instanceof String) {
                 console.log(
                      '%cdata：' + res.data.result,
                      'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               } else if (res.data && res.data.result) {
                 console.log(
                      '%cdata：' + res.data.result,
                      'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               }
               console.log(
                    '%c-------------------------------------------------------------------',
                    'font-weight:700;'
               )
               console.groupEnd()
               if ((res.data && typeof res.data.result == 'string') || (res.data && res.data.msg)) {
                 // Message.success(res.data.result || res.data.msg)
               }
               resolve(res)
             } else {
               // Message.error(res.data.msg || '错误')
               resolve(res)
               reject(res.data.msg)
             }
           })
           .catch((error) => {
             if (process.env.NODE_ENV === 'production') return
             console.dir(error)
             console.group('%c' + url + '  POST', 'font-weight:900;color:red;')
             console.log(
                  '%cdata：' + (error.response == undefined ? error.name : error.response.config.data),
                  'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cerror：' + (error.response ? error.response.data.error : error.message),
                  'background-color:#DC5145;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cstatus：' + (error.response ? error.response.status : error.code),
                  'background-color:#FDCC41;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cmessage：' + error.message,
                  'background-color:#4D8BF2;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%c-------------------------------------------------------------------',
                  'font-weight:700;'
             )
             console.groupEnd()
             if (error.response) {
               msg = status[error.response.status]
             } else {
               msg = error.message
             }
             reject(error)
           })
    })
  },
  form(url, e, param = {}, type = 'post') {
    delete param._rowKey
    delete param._index
    let formData = new FormData()
    let keys = Object.keys(param)
    keys.map((v) => {
      formData.append(v, param[v])
    })
    if (e && e.length) { // 判断是否是多图上传 多图则循环添加进去
      e.forEach(item => {
        formData.append("fileList", item) //第一个参数字符串可以填任意命名，第二个根据对象属性来找到file
      })
    } else {
      formData.append("file", e)
    }
    return new Promise((resolve, reject) => {
      service({
        method: type,
        url,
        params: formData,
        data: formData
      })
           .then((res) => {
             console.log('res: ', res)
             if (
                  (res.status == 200 && res.data && res.data.code == 0) ||
                  (res.status == 200 && res.data == null)
             ) {
               console.groupCollapsed('%c' + url + '  POST', 'font-weight:900;')
               if (res.data && res.data.result instanceof Array) {
                 res.data.result.map((v) => {
                   console.log(
                        '%cdataObj：' + JSON.stringify(v, null, 2),
                        'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                   )
                 })
               } else if (res.data && res.data.result instanceof Object) {
                 console.log(
                      '%cdataObj：' + JSON.stringify(res.data.result, null, 2),
                      'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               } else if (res.data && res.data.result instanceof String) {
                 console.log(
                      '%cdata：' + res.data.result,
                      'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               } else if (res.data && res.data.result) {
                 console.log(
                      '%cdata：' + res.data.result,
                      'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
                 )
               }
               console.log(
                    '%c-------------------------------------------------------------------',
                    'font-weight:700;'
               )
               console.groupEnd()
               if ((res.data && typeof res.data.result == 'string') || (res.data && res.data.msg)) {
                 // Message.success(res.data.result || res.data.msg)
               }
               resolve(res)
             } else {
               // Message.error(res.data.msg || '错误')
               resolve(res)
               reject(res.data.msg)
             }
           })
           .catch((error) => {
             if (process.env.NODE_ENV === 'production') return
             console.dir(error)
             console.group('%c' + url + '  POST', 'font-weight:900;color:red;')
             console.log(
                  '%cdata：' + (error.response == undefined ? error.name : error.response.config.data),
                  'background-color:#159E5C;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cerror：' + (error.response ? error.response.data.error : error.message),
                  'background-color:#DC5145;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cstatus：' + (error.response ? error.response.status : error.code),
                  'background-color:#FDCC41;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%cmessage：' + error.message,
                  'background-color:#4D8BF2;color:white;height:16px;border-radius:4px;padding:2px 4px;'
             )
             console.log(
                  '%c-------------------------------------------------------------------',
                  'font-weight:700;'
             )
             console.groupEnd()
             if (error.response) {
               msg = status[error.response.status]
             } else {
               msg = error.message
             }
             reject(error)
           })
    })
  },
  patch(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'patch',
        url,
        data: param
      })
           .then((res) => {
             if ((res.status == 200)) {
               resolve(res)
             } else {
               resolve(res)
               reject(res.data.msg)
             }
           })
           .catch((error) => {
             if (process.env.NODE_ENV === 'production') return
             reject(error)
           })
    })
  },
  delete(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'delete',
        url,
        params: param,
        cancelToken: new CancelToken((c) => {
          cancel = c
        })
      })
           .then((res) => {
             if (!res.data) {
               resolve(res)
               return
             }
             if (res.status == 200) {
               resolve(res)
             } else {
               reject(res.data.msg)
             }
           })
           .catch((error) => {
             if (process.env.NODE_ENV === 'production') return
             reject(error)
           })
    })
  },
  put(url, param = {}) {
    delete param._rowKey
    delete param._index
    return new Promise((resolve, reject) => {
      service({
        method: 'put',
        url,
        params: param,

        cancelToken: new CancelToken((c) => {
          cancel = c
        })
      })
           .then((res) => {
             if (!res.data) {
               resolve(res)
               return
             }
             if (res.status == 200) {
               resolve(res)
             } else {
               reject(res.data.msg)
             }
           })
           .catch((error) => {
             if (process.env.NODE_ENV === 'production') return
             reject(error)
           })
    })
  },
}
*/
